package br.com.negocio;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.pessoa.Pessoa;
import br.com.util.HibernateUtil;
import br.com.venda.ItemVenda;
import br.com.venda.Venda;

public class VendaService {

	public void salvarVenda(Venda venda){
		
		Session session = HibernateUtil.getSession();
		Transaction tx = session.beginTransaction();
		session.saveOrUpdate(venda);
		tx.commit();
		session.close();
	}
	
	public void salvarItem(ItemVenda venda){
		
		Session session = HibernateUtil.getSession();
		Transaction tx = session.beginTransaction();
		session.saveOrUpdate(venda);
		tx.commit();
		session.close();
	}
	
	public ItemVenda bucarItemId(int codigo){
		
		ItemVenda itemVenda;
		Session session = HibernateUtil.getSession();
		try {
			itemVenda = (ItemVenda) session.get(ItemVenda.class, codigo);
		} finally {
			session.close();
		}
		
		return itemVenda;
	}
	
	public Venda bucarVendaId(int codigo){
		
		Session session = HibernateUtil.getSession();
		try {
			return (Venda) session.get(Venda.class, codigo);
		} finally {
			//xD
		}
	}
}
